package org.ocean.online.user.initdb;

import java.io.File;
import java.net.URI;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.ocean.online.sys.BusinessException;
import org.ocean.online.sys.DbGuard;
import org.ocean.online.sys.DbGuardFactory;

public class InitUserAction {

	public static void init(Map<String,Object> user){
		
		DbGuard guard = DbGuardFactory.getDbGuard(user);
		try {
			URI filepath = InitUserAction.class.getResource("."+File.separator+"hsql.sql").toURI();
			System.out.println("init sql path :" + filepath);
			File file = new File(filepath);
			String script = FileUtils.readFileToString(file);
			guard.execute(script);
		} catch (Exception e) {
			throw new BusinessException("初始化数据库失败",e);
		}
	}
}
